﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Caching;

namespace WebAppMatrix.Caching
{
    public abstract class CacheBase
    {
        public abstract T Get<T>(string key, params object[] keyArgs);

        public abstract T Fetch<T>(string key, Func<T> callIfGetReturnsNull, params object[] keyArgs);
        public abstract T Fetch<T>(string key, Func<T> callIfGetReturnsNull, DateTime absoluteExpiration, params object[] keyArgs);
        public abstract T Fetch<T>(string key, Func<T> callIfGetReturnsNull, TimeSpan slidingExpiration, params object[] keyArgs);

        public abstract T Fetch<T>(string key, Action<T> callIfGetReturnsValue, Func<T> callIfGetReturnsNull, params object[] keyArgs);
        public abstract T Fetch<T>(string key, Action<T> callIfGetReturnsValue, Func<T> callIfGetReturnsNull, DateTime absoluteExpiration, params object[] keyArgs);
        public abstract T Fetch<T>(string key, Action<T> callIfGetReturnsValue, Func<T> callIfGetReturnsNull, TimeSpan slidingExpiration, params object[] keyArgs);

        public abstract void Insert(string key, object data, params object[] keyArgs);
        public abstract void Insert(string key, object data, DateTime absoluteExpiration, params object[] keyArgs);
        public abstract void Insert(string key, object data, TimeSpan slidingExpiration, params object[] keyArgs);

        public abstract void Remove(string key, params object[] keyArgs);
        public abstract void RemoveAll();

        public abstract int Count();

        public static string BuildKey(string key, params object[] keyArgs)
        {
            return (keyArgs == null || keyArgs.Length == 0) ? key : string.Format(key, keyArgs);
        }
    }
}
